from crawler_core.event.event_init import EventDown, EventSearch, EventSearchSecond
from crawler_core.event.task.task_api import TaskAPI
from crawler_core.event.task.task_download import TaskDownload
from crawler_core.event.task.task_login import TaskLogin
from crawler_core.event.task.task_search import TaskSearch
from lib.sys.scheduler_config import SchedulerConfig
from lib.utils.print_util import PrintUtil

'''
*************************************************************
******  调度--下载服务                                *******
******  crawler_core.event.task.task_download         *******
******  crawler_core.event.task.task_download         *******
******  crawler_core.event.task.task_download         *******
*************************************************************
'''


def down_task():
    task = TaskDownload()
    task.start()


def startDown():
    PrintUtil.start("start download server ...")
    SchedulerConfig.add_job_start(down_task, "down_task")
    PrintUtil.start("start download server success ...")



'''
*************************************************************
******  调度--查询服务                                *******
******  crawler_core.event.task.task_download         *******
******  crawler_core.event.task.task_download         *******
******  crawler_core.event.task.task_download         *******
*************************************************************
'''

def search_task():
    task = TaskSearch()
    task.start()


def startSearch():
    PrintUtil.start("start search server ...")
    SchedulerConfig.add_job_start(search_task, "search_task")
    PrintUtil.start("start search server success ...")


'''
*************************************************************
******  调度--登录服务                                *******
******  crawler_core.event.task.task_download         *******
******  crawler_core.event.task.task_download         *******
******  crawler_core.event.task.task_download         *******
*************************************************************
'''


def login_task():
    task = TaskLogin()
    task.start()


def startLogin():
    PrintUtil.start("start Login server ...")
    SchedulerConfig.add_job_start(login_task, "login_task")
    PrintUtil.start("start Login server success ...")


'''
***********************************************************************
******  调度--API服务                                            ******
******  1.   startApi                   返回数据                 ******
******  2.   startEventDown             下载任务生产者           ******
******  3.1. startEventSearch           查询任务生产者           ******
******  3.2. startEventSearchSecond     查询任务分片             ******
***********************************************************************
'''


def startApi():
    # startApiReturn()
    # startEventDown()
    startEventSearch()
    startEventSearchSecond()


'''
**************************************
******  1.   api_task           ******
**************************************
'''


def api_task():
    task = TaskAPI()
    task.start()


def startApiReturn():
    PrintUtil.start("start Api server...")
    SchedulerConfig.add_job_start(api_task, "api_task")
    PrintUtil.start("start Api server success ...")


'''
***************************************
******  2.   event_down          ******
***************************************
'''


def event_down():
    event = EventDown()
    event.start()


def startEventDown():
    PrintUtil.start("start event download server ...")
    SchedulerConfig.add_job_start(event_down, "event_down")
    PrintUtil.start("start event download success ...")


'''
*****************************************
******  3.1. startEventSearch      ******
*****************************************
'''


def event_search():
    event = EventSearch()
    event.start()


def startEventSearch():
    PrintUtil.start("start event search server ...")
    SchedulerConfig.add_job_start(event_search, "event_search")
    PrintUtil.start("start event search success ...")


'''
**********************************************
******  3.2. startEventSearchSecond     ******
**********************************************
'''


def event_search_second():
    event = EventSearchSecond()
    event.start()


def startEventSearchSecond():
    PrintUtil.start("start event search server ...")
    SchedulerConfig.add_job_start(event_search_second, "event_search_second")
    PrintUtil.start("start event search success ...")